<template>
    <view :style="objColor">
        <!-- mine/pages/reRecord/reRecord.wxml -->
        <view class="reRecordBox">
            <view class="screen">
                <view class="type" @tap="checkType">
                    {{ typeName }}
                    <image class="img" src="https://oos-cn.ctyunapi.cn/front-end/static/static/xiala.png"></image>
                </view>
                <view class="type" @tap="checkTime">
                    {{ time }}
                    <image class="img" src="https://oos-cn.ctyunapi.cn/front-end/static/static/xiala.png"></image>
                </view>
            </view>
            <view class="statistics">
                <view>
                    <view class="statisticsNum">+{{ accountFlowStatisticsMiniVO.chargeTotalStr?accountFlowStatisticsMiniVO.chargeTotalStr:0 }}</view>
                    <view class="statisticsTxt">{{ accountType == '2' ? '分配' : '充值' }}</view>
                </view>
                <view>
                    <!-- <view class="statisticsNum">{{ accountFlowStatisticsMiniVO.awardTotalStr }}</view> -->

                    <!-- 外包的奖励金余额 -->
                    <!-- <view class="statisticsNum" v-if="!totalBonusRecord">{{ accountFlowStatisticsMiniVO.awardTotalStr?accountFlowStatisticsMiniVO.awardTotalStr:0 }}</view>
                    <view class="statisticsNum" v-if="totalBonusRecord">{{ totalBonusRecord?totalBonusRecord:0 }}</view> -->

                    <!-- 营销获客2.0去取平台自己的收支明细 -->
                    <view class="statisticsNum">{{ accountFlowStatisticsMiniVO.awardTotalStr?accountFlowStatisticsMiniVO.awardTotalStr:0 }}</view>

                    <view class="statisticsTxt">奖励</view>
                </view>
                <view>
                    <view class="statisticsNum">{{ accountFlowStatisticsMiniVO.consumptionTotalStr ? accountFlowStatisticsMiniVO.consumptionTotalStr : 0 }}</view>
                    <view class="statisticsTxt">消费</view>
                </view>
                <view>
                    <view class="statisticsNum">{{ accountFlowStatisticsMiniVO.refundTotalStr?accountFlowStatisticsMiniVO.refundTotalStr:0 }}</view>
                    <view class="statisticsTxt">退款</view>
                </view>
            </view>
            <view class="record">
                <view class="record_item" v-if="recordsList.length > 0" v-for="(item, index) in recordsList" :key="index">
                    <view class="itemDisplay">
                        <view class="itemTitle">
                            <view class="name">
                                {{ item.eventNameStr }}
                                <!-- <text v-if="item.busId">({{ item.busId }})</text> -->
                            </view>

                            <view class="event tkhx" v-if="item.refundRemark != null">退款核销</view>
                            <view class="event" v-if="item.eventNameDetailStr">{{ item.eventNameDetailStr }}</view>
                        </view>
                        <view :class="item.amountChange > 0 ? 'changeAmount1' : 'changeAmount'">{{ item.amountChange > 0 ? '+' + item.amountChange : item.amountChange }}</view>
                    </view>

                    <view class="itemDisplay">
                        <view class="balance">
                            余额：
                            <view class="money">{{ item.accountBalance }}</view>
                        </view>
                        <view class="time">{{ item.createTime }}</view>
                    </view>
                </view>
                <view v-if="loadAll" class="noList">{{ tips }}</view>
                <view v-if="recordsList.length == 0">
                    <Upgrading text="暂无收支记录" text1=" "></Upgrading>
                    <view class="goCharing" @tap="goCharing">去充电</view>
                </view>
                <!-- <view class="record_item">
      <view class="itemDisplay">
        <view class="itemTitle"><view class="name">南方众悦奥体充电站南方众悦奥体充电站</view><view class="tag">退款核销</view></view>
        <view class="changeAmount1">+79.25</view>
      </view>
      <view class="itemDisplay">
        <view class="balance">余额：<view class="money">46.20</view>
        </view>
        <view class="time">2022-05-20 13:23:23</view>
      </view>
    </view> -->
            </view>
        </view>
    <!--    <u-popup :show="showTime" mode="bottom"  @close="onClose" closeOnClickOverlay :round="16"> -->
			<!-- <view style="margin:24rpx;width: 702rpx;box-sizing: border-box;border-radius: 16rpx;" v-show="showTime"> -->
			    <u-datetime-picker :itemHeight="100" :show="showTime" mode="year-month" v-model="currentDate"  @change="onInput" @cancel="onCancel" @confirm="onConfirm" closeOnClickOverlay/>
			<!-- </view> -->
    <!--    </u-popup> -->
        <u-popup :show="showType" closeOnClickOverlay mode="top" @close="onClose"  customStyle="margin:88rpx 24rpx 0;width:702rpx;box-sizing: border-box;border-radius: 16rpx;">
			<view class="popType">
                <view :class="'all ' + (typeIndex == 0 ? 'checkSel' : '')" @tap="enterType" data-index="0" data-name="全部">全部</view>
                <view class="popType_r">
                    <view class="pup1">
                        <view :class="'puptxt ' + (typeIndex == 1 ? 'checkSel' : '')" @tap="enterType" data-index="1" data-name="充值">充值</view>
                        <view :class="'puptxt1 ' + (typeIndex == 2 ? 'checkSel' : '')" @tap="enterType" data-index="2" data-name="奖励">奖励</view>
                    </view>
                    <view class="pup1">
                        <view :class="'puptxt ' + (typeIndex == 3 ? 'checkSel' : '')" @tap="enterType" data-index="3" data-name="消费">消费</view>
                        <view :class="'puptxt1 ' + (typeIndex == 4 ? 'checkSel' : '')" @tap="enterType" data-index="4" data-name="退费">退费</view>
                    </view>
					<!-- <view class="pup2"> -->
					    <!-- <view :class="'puptxt ' + (typeIndex == 5 ? 'checkSel' : '')" @tap="enterType" data-index="5" data-name="个人">个人</view> -->
					    <!-- <view :class="'puptxt1 ' + (typeIndex == 6 ? 'checkSel' : '')" @tap="enterType" data-index="6" data-name="人保">人保</view> -->
					<!-- </view> -->
                </view>
            </view>
        </u-popup>
        <u-popup :show="showType1" closeOnClickOverlay mode="top" @close="onClose" :round="16">
            <view class="popType" style="width:702rpx;margin:88rpx 24rpx 0;box-sizing: border-box;">
                <view :class="'all1 ' + (typeIndex == 0 ? 'checkSel' : '')" @tap="enterType" data-index="0" data-name="全部">全部</view>
                <view :class="'puptxt2 ' + (typeIndex == 3 ? 'checkSel' : '')" @tap="enterType" data-index="3" data-name="消费">消费</view>
                <view :class="'puptxt3 ' + (typeIndex == 4 ? 'checkSel' : '')" @tap="enterType" data-index="4" data-name="退费">退费</view>
            </view>
        </u-popup>
    </view>
</template>

<script>
'use strict';
import Upgrading from '../../../components/upgrading/upgrading';

// exports.__esModule = true; // mine/pages/reRecord/reRecord.ts
const app = getApp();

function shijianc(time) {
    var date = new Date(time);
    var Y = date.getFullYear();
    var M = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
    return Y + '年' + M + '月';
}

function shijianc1(time) {
    var date = new Date(time);
    var Y = date.getFullYear();
    var M = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
    return Y + '-' + M;
}

var https_1 = require('./../../../api/https.js');




export default {
    components: {
        Upgrading
    },
    data() {
        return {
            showType: false,
            showType1: false,
            showTime: false,
            loadAll: true,
            typeIndex: 0,
            typeName: '全部',
            current: 1,
            pages: 1,
            accountType: 1,
            size: 10,
            recordsList: [],
            currentDate: new Date().getTime(),

            // minDate: new Date().getTime(),
            time: shijianc(new Date().getTime()),

            date: shijianc1(new Date().getTime()),
            tips: '',

            accountFlowStatisticsMiniVO: {
                chargeTotalStr: '',
                awardTotalStr: '',
                consumptionTotalStr: false,
                refundTotalStr: ''
            },
			newRecordsList:[],
			oldRecordsList:[],
            totalBonusRecord: '',

            minDate: ''
        };
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
		console.log(options)
        if (options.accountType) {
			console.log('jinr ')
            this.setData({
                accountType: options.accountType
            });
        }
		if(options.typeIndex){
			if(options.typeIndex==='2'){
				this.setData({
					// 0 全部  1 充值 2 奖励 3 消费 4 退费
					typeIndex: options.typeIndex,
					typeName : '奖励'
				});
			}else if(options.typeIndex==='5'){
				this.setData({
					// 0 全部  1 充值 2 奖励 3 消费 4 退费
					typeIndex: options.typeIndex,
					typeName : '个人'
				});
			}else if(options.typeIndex==='6'){
				this.setData({
					// 0 全部  1 充值 2 奖励 3 消费 4 退费
					typeIndex: options.typeIndex,
					typeName : '人保'
				});
			}
		}
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.getPageList('replace');
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        if (this.current == this.pages) {
            // 到底
			this.loadAll = true
			this.tips = '已加载全部订单！'
        } else {
			this.current = ++this.current
			this.size = 10
            this.getPageList('');
        }
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {
        //收支记录 营销获客2.0去取平台自己的收支明细
        getPageList: function (type) {
            var that = this;
            uni.showLoading({
                title: '加载中...',
                mask: true
            });
            https_1
                .pageList({
                    accountType: this.accountType,
                    tab: this.typeIndex === '5' ?1:this.typeIndex*1+1,
                    current: this.current,
                    size: this.size,
                    date: this.date
                })
                .then((res)=> {
                    console.log('res===>>>>>>>',res)
                    
                    var data = res.data.accountFlowMiniVO.records;
                    data.forEach(function (element) {
                        element.amountChange = (element.amountChange / 100).toFixed(2);
                        element.accountBalance = (element.accountBalance / 100).toFixed(2);
                    });
                    var data1 = res.data.accountFlowStatisticsMiniVO;

                    if (data1.chargeTotalStr) {
                        data1.chargeTotalStr = data1.chargeTotalStr / 100;
                    } else {
                        data1.chargeTotalStr = 0;
                    } //充值统计

                    if (data1.awardTotalStr) {
                        data1.awardTotalStr = data1.awardTotalStr / 100;
                    } else {
                        data1.awardTotalStr = 0;
                    } //奖励统计

                    if (data1.consumptionTotalStr) {
                        data1.consumptionTotalStr = data1.consumptionTotalStr / 100;
                    } else {
                        data1.consumptionTotalStr = 0;
                    } //消费统计

                    if (data1.refundTotalStr) {
                        data1.refundTotalStr = data1.refundTotalStr / 100;
                    } else {
                        data1.refundTotalStr = 0;
                    } //退款统计
                    that.current = res.data.accountFlowMiniVO.current
					that.pages = res.data.accountFlowMiniVO.pages
					that.accountFlowStatisticsMiniVO = data1
                    if (type === 'replace') {
						that.recordsList = data
                    } else {
						that.recordsList = that.recordsList.concat(data)
                    }

                    uni.hideLoading();
                })
                ['catch'](function (res) {
                    uni.hideLoading();
                });
        },

        //收支记录
        // getPageList(type) {
        //     pageList({
        //         accountType: this.accountType,
        //         tab: this.typeIndex * 1 + 1,
        //         //全部类型
        //         current: 1,
        //         size: 10000,
        //         date: this.date
        //     })
        //         .then((res) => {
        //             console.log('res===>>>>>>>',res)
        //             if (res.code == 0) {
        //                 console.log(res.data, '自己接口返回收支记录.....');
        //                 let data = res.data.accountFlowMiniVO.records;
        //                 data.forEach((element) => {
        //                     element.amountChange = (element.amountChange / 100).toFixed(2);
        //                     element.accountBalance = (element.accountBalance / 100).toFixed(2);
        //                 });
        //                 let data1 = res.data.accountFlowStatisticsMiniVO;
        //                 if (data1.chargeTotalStr) {
        //                     data1.chargeTotalStr = data1.chargeTotalStr / 100;
        //                 } else {
        //                     data1.chargeTotalStr = 0;
        //                 } //充值统计
        //                 if (data1.awardTotalStr) {
        //                     data1.awardTotalStr = data1.awardTotalStr / 100;
        //                 } else {
        //                     data1.awardTotalStr = 0;
        //                 } //奖励统计
        //                 if (data1.consumptionTotalStr) {
        //                     data1.consumptionTotalStr = data1.consumptionTotalStr / 100;
        //                 } else {
        //                     data1.consumptionTotalStr = 0;
        //                 } //消费统计
        //                 if (data1.refundTotalStr) {
        //                     data1.refundTotalStr = data1.refundTotalStr / 100;
        //                 } else {
        //                     data1.refundTotalStr = 0;
        //                 } //退款统计
        //                 this.setData({
        //                     current: res.data.accountFlowMiniVO.current,
        //                     pages: res.data.accountFlowMiniVO.pages,
        //                     // recordsList:data,
        //                     accountFlowStatisticsMiniVO: data1
        //                 });
        //                 this.setData({
        //                     oldRecordsList: data
        //                 });
        //                 if(this.marketingSwitch) {
        //                     userPageBonusRecord({
        //                         accountType: this.accountType,
        //                         current: 1,
        //                         date: this.date,
        //                         plUserId: uni.getStorageSync('memberId'),
        //                         sellerId: app.globalData.sellerId,
        //                         size: 10000,
        //                         tab: this.typeIndex * 1 + 1 //全部类型
        //                     })
        //                         .then((res) => {
        //                             console.log(res.data.records, '奖励金外包接口返回.....');
        //                             let data = res.data.records;
        //                             // data.forEach((element) => {
        //                             //   element.amountChange = (element.amountChange / 100).toFixed(2)
        //                             //   element.accountBalance = (element.accountBalance / 100).toFixed(2)
        //                             // });
        //                             this.setData({
        //                                 newRecordsList: data
        //                             });

        //                             // 合并收支记录
        //                             this.mergeData();
        //                         })
        //                         .catch((err) => {
        //                             console.log(err);
        //                         });
        //                     userTotalBonusRecord({
        //                         accountType: this.accountType,
        //                         current: 1,
        //                         date: this.date,
        //                         plUserId: uni.getStorageSync('memberId'),
        //                         sellerId: app.globalData.sellerId,
        //                         size: 10000,
        //                         tab: this.typeIndex * 1 + 1 //全部类型
        //                     })
        //                         .then((res) => {
        //                             console.log(res.data, 'wb奖励金余额22222');
        //                             // console.log(this.data.accountFlowStatisticsMiniVO,'原先的奖励金余额')

        //                             // let jlTotal = this.data.accountFlowStatisticsMiniVO.awardTotalStr + res.data;//原先的奖励金余额
        //                             // console.log(jlTotal)

        //                             this.setData({
        //                                 totalBonusRecord: res.data
        //                             });
        //                         })
        //                         .catch((err) => {
        //                             console.log(err);
        //                             // 合并收支记录
        //                             this.mergeData();
        //                         });
        //                 }else{
		// 					this.mergeData();
		// 				}
        //             }
        //         })
        //         .catch((err) => {
        //             console.log(err);
        //         });
        // },

        //合并收支记录
        mergeData() {
            let recordsLists = [...this.oldRecordsList, ...this.newRecordsList];
            recordsLists.sort((a, b) => {
                let t1 = new Date(Date.parse(a.createTime.replace(/-/g, '/')));
                let t2 = new Date(Date.parse(b.createTime.replace(/-/g, '/')));
                return t2.getTime() - t1.getTime();
            });
            console.log(recordsLists, '合并啊.......');
            this.setData({
                recordsList: recordsLists
                // pageNum
            });
        },

        //选择收支记录类型
        enterType: function (e) {
            var index = e.currentTarget.dataset.index;
            var name = e.currentTarget.dataset.name;
			this.typeIndex = index
			this.typeName = name
			this.current = 1
			this.showType = false
			this.showType1 = false
			this.loadAll = false
            this.getPageList('replace');
        },

        //展开显示收支记录类型
        checkType: function () {
            if (this.accountType == 1) {
				this.showType = true
            } else {
				this.showType1 = true
            }
        },

        onClose: function () {
            if (this.accountType == 1) {
				this.showType = false
            } else {
				this.showType1 = false
            }
        },

        //选择时间
        checkTime: function () {
			this.showTime = true
        },

        onInput: function (event) {
			console.log(event,'年月')
			this.currentDate = event.value
        },

        onCancel: function () {
			this.showTime = false
        },

        onConfirm: function () {
			this.showTime = false
			this.loadAll = false
			this.current = 1
			this.time = shijianc(this.currentDate)
			this.date = shijianc1(this.currentDate)
            this.getPageList('replace');
        },

        //去充电
        goCharing: function () {
            uni.redirectTo({
                url: '/packageFunctional/sitelist/sitelist'
            });
        }
    }
};
</script>
<style lang="less">
@import url('reRecord.less');


//营销获客处理
.event {
    background: rgba(252, 114, 76, 0);
    border: 1px solid rgba(20, 135, 250, 0.8000);
    border-radius: 16rpx;
    padding: 0 10rpx;
    font-size: 22rpx;
    color: #1487FA;
    margin-left: 20rpx;
}

.tkhx{
    border: 1px solid rgba(252,114,76,0.8)!important;
    color: #FC724C!important;
}
</style>
